package com.advert.service.support;

import com.advert.dto.ModelSearchCriteria;
import com.advert.model.support.*;
import com.advert.provider.support.SupportProvider;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;

import java.io.Serializable;
import java.util.*;

@Name("SupportService")
@Scope(ScopeType.EVENT)
@AutoCreate
public class SupportService implements Serializable {
    @In("SupportProvider")
    private SupportProvider supportProvider;

    public List<VehicleTypeEntity> getVehicleTypes() {
        return supportProvider.getVehicleTypes();
    }

    public Map<String, List<VehicleCategoryEntity>> getVehicleCategories() {
        Map<String, List<VehicleCategoryEntity>> retVal = new HashMap<String, List<VehicleCategoryEntity>>();
        retVal.put(null, Collections.<VehicleCategoryEntity>emptyList());
        
        List<VehicleCategoryEntity> categories = supportProvider.getVehicleCategories();
        for (VehicleCategoryEntity category : categories) {
             List<VehicleCategoryEntity> current = retVal.get(category.getTypeCode());
            if (current == null) {
                current = new ArrayList<VehicleCategoryEntity>();
                retVal.put(category.getTypeCode(), current);
            }
            current.add(category);
        }
        return retVal;
    }

    public Map<String, List<VehicleBrandEntity>> getVehicleBrands() {
        Map<String, List<VehicleBrandEntity>> retVal = new HashMap<String, List<VehicleBrandEntity>>();
        List<VehicleBrandEntity> brands = supportProvider.getVehicleBrands();
        for (VehicleBrandEntity brand : brands) {
             List<VehicleBrandEntity> current = retVal.get(brand.getTypeCode());
            if (current == null) {
                current = new ArrayList<VehicleBrandEntity>();
                retVal.put(brand.getTypeCode(), current);
            }
            current.add(brand);            
        }
        return retVal;
    }

    public List<VehicleModelEntity> searchVehicleModels(ModelSearchCriteria criteria) {
        return supportProvider.searchVehicleModels(criteria);
    }

    public List<CurrencyEntity> getCurrencies() {
        return supportProvider.getCurrencies();
    }

    public List<VehicleStateEntity> getVehicleStates() {
        return supportProvider.getVehicleStates();
    }

    public List<RegionEntity> getRegions() {
        return supportProvider.getRegions();
    }
}
